package com;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 用callable创建线程的例子
 */
public class CallableDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        call c = new call();
        FutureTask<String> ft = new FutureTask<>(c);
        new Thread(ft,"A").start();
        String s = ft.get();
        System.out.println(s);
    }

}

class call implements Callable<String>{

    public String call() throws Exception {
        int num = 0;
        for(int i=0;i<10;i++){
            System.out.println(Thread.currentThread().getName() + i);
            num+=i;
        }
        return num + "";
    }
}
